package huzh.foundation.pool.threadpool;

import java.io.Serializable;

import huzh.foundation.pool.inf.IObject;
import huzh.foundation.pool.inf.ParaRunnable;

/**
 *<p>title:AbstractTask</p>
 *<p>description:</p>
 * @since 2014-5-26
 * @author huzh
 * @version 1.0
 */
public abstract class AbstractTask implements ParaRunnable, Runnable, IObject, Serializable{
    /** serialVersionUID*/
    private static final long serialVersionUID = 3641856128298484172L;
    /** result*/
    private Object result = null;
    /** isDone*/
    private boolean isDone = false;

    /**
     * @param paramLong
     */
    protected void delay(long paramLong){
        try{
            Thread.currentThread(); 
            Thread.sleep(paramLong);
            return;
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    /**
     * @return
     */
    public Object getResult(){
        return this.result;
    }

    /**
     * @return
     */
    public boolean isDone(){
        return this.isDone;
    }

    /**
     * join
     */
    public void join(){
        while (!isDone())
            delay(10L);
    }

    public abstract void reset();

    /**
     * run
     */
    public void run(){
        run(null);
    }

    public abstract void run(Object paramObject);

    /**
     * @param paramBoolean
     */
    protected void setDone(boolean paramBoolean){
        this.isDone = paramBoolean;
    }

    /**
     * @param result
     */
    protected void setResult(Object result){
        this.result = result;
    }
}
